import  pymysql
from  bilibili_update import get_tag,get_tag_id_from_mysql
from  mysql_conf import mysel_conf
import time
conn = mysel_conf.pool()
cursor = conn.cursor()


def get_blilbili_content_id():
    sql="SELECT id,thirdparty_id FROM contents  where pic_link like 'https://m.bilibili.com/video/av%' and thirdparty_id >0 and thirdparty_id<100000000   and thirdparty_id!='14' "
    cursor.execute(sql)
    res=cursor.fetchall()
    return res
def main():
    res=get_blilbili_content_id()
    for i in res:
        tag=get_tag(i['thirdparty_id'])
        print(i)
        for t in get_tag_id_from_mysql(tag):
            sql='SELECT * from contents_tag where content_id=%s and tag_id=%s'
            cursor.execute(sql,(i['id'],t))
            res = cursor.fetchone()
            if res:
                print(res)
                continue
            else:
                sql_insert='Insert into contents_tag(content_id,tag_id,name, created_at,updated_at) values(%s,%s,%s,%s,%s)'
                time_now=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
                print(time_now)
                cursor.execute(sql_insert, (int(i["id"]), int(t),' ' ,time_now,time_now))
                conn.commit()
    cursor.close()
    conn.close()
if __name__ == '__main__':
    main()